package cn.net.wangyixinwen.mvvm.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;

import java.util.List;

import cn.net.wangyixinwen.R;
import cn.net.wangyixinwen.bean.OrderBean;

public class OrderAdapter extends RecyclerView.Adapter<OrderAdapter.ViewHolder>{
    private List<OrderBean.ListDTO> list ;
    private Context context ;

    public OrderAdapter(List<OrderBean.ListDTO> list, Context context) {
        this.list = list;
        this.context = context;
    }
    public void updateAdapter(List<OrderBean.ListDTO> list){
        this.list = list ;
        notifyDataSetChanged();
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = View.inflate(context,R.layout.item_order,null) ;
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        OrderBean.ListDTO orderBean = list.get(position) ;
        Glide.with(context)
                .load(orderBean.getCoverPath())
                .into(holder.imageView) ;
        holder.textView.setText(orderBean.getTitle());
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    static  class ViewHolder extends RecyclerView.ViewHolder{

        ImageView imageView ;
        TextView textView ;
        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            imageView = itemView.findViewById(R.id.order_image) ;
            textView = itemView.findViewById(R.id.order_name) ;
        }
    }
}
